import unittest
import requests
from ddt import ddt, data, unpack,file_data
from unit__001.unit_03.excel import excel

path = r'/unit__001/unit__003/data.xlsx'
sheetname = 'Sheet1'
dy = excel(path, sheetname)


@ddt
class MyTestCase(unittest.TestCase):
    def setUp(self) -> None:
        print('start case')

    def tearDown(self) -> None:
        print('end case')

    token=None
    @data(*dy.get_data())
    @unpack
    def test_01(self, username, password,hopt):
        url = 'http://10.59.9.14:7003/api/public/login'
        json = {"username": username, "password": password}
        login = requests.post(url=url, json=json)
        print(login.json())
        if hopt == '正':
            # 提取token
            MyTestCase.token=login.json()['data']['token']
            print(MyTestCase.token)
        else:
            return

    @file_data('data.json')
    def test_02(self, id, num):
        url = 'http://10.59.9.14:7003/api/cart/add'
        headers={'auth-token':'Bearer '+MyTestCase.token}
        json = {
            "id": id,
            "sku_id": "",
            "num": num
        }
        login = requests.post(url=url,headers=headers, json=json)
        print(login.json())


if __name__ == '__main__':
    unittest.main()
